package com.ruralflow.flow.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruralflow.flow.domain.vo.FlowApplyApproveReqVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruralflow.common.annotation.Log;
import com.ruralflow.common.core.controller.BaseController;
import com.ruralflow.common.core.domain.AjaxResult;
import com.ruralflow.common.enums.BusinessType;
import com.ruralflow.flow.domain.FlowApply;
import com.ruralflow.flow.service.IFlowApplyService;
import com.ruralflow.common.utils.poi.ExcelUtil;
import com.ruralflow.common.core.page.TableDataInfo;

/**
 * 流动申请Controller
 * 
 * @author ruralflow
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/flow/flowApply")
public class FlowApplyController extends BaseController
{
    @Autowired
    private IFlowApplyService flowApplyService;

    /**
     * 查询流动申请列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowApply flowApply)
    {
        startPage();
        List<FlowApply> list = flowApplyService.selectFlowApplyList(flowApply);
        return getDataTable(list);
    }

    /**
     * 导出流动申请列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:export')")
    @Log(title = "流动申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowApply flowApply)
    {
        List<FlowApply> list = flowApplyService.selectFlowApplyList(flowApply);
        ExcelUtil<FlowApply> util = new ExcelUtil<FlowApply>(FlowApply.class);
        util.exportExcel(response, list, "流动申请数据");
    }

    /**
     * 获取流动申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(flowApplyService.selectFlowApplyByApplyId(applyId));
    }

    /**
     * 新增流动申请
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:add')")
    @Log(title = "流动申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowApply flowApply)
    {
        return toAjax(flowApplyService.insertFlowApply(flowApply));
    }

    /**
     * 修改流动申请
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:edit')")
    @Log(title = "流动申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowApply flowApply)
    {
        return toAjax(flowApplyService.updateFlowApply(flowApply));
    }

    /**
     * 删除流动申请
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:remove')")
    @Log(title = "流动申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(flowApplyService.deleteFlowApplyByApplyIds(applyIds));
    }

    /**
     * 流动申请审批
     */
    @PreAuthorize("@ss.hasPermi('flow:flowApply:edit')")
    @Log(title = "流动申请", businessType = BusinessType.UPDATE)
    @PutMapping("/approve")
    public AjaxResult approve(@RequestBody FlowApplyApproveReqVO flowApplyApproveReqVO)
    {
        return toAjax(flowApplyService.approveFlowApply(flowApplyApproveReqVO));
    }
}
